package com.situ.student.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.student.entity.Student;
import com.situ.student.service.IStudentService;
import com.situ.student.service.impl.StudentServiceImpl;

public class AddStudentServlet extends HttpServlet {
	private IStudentService studentService = new StudentServiceImpl();//studentService拿过来

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//1、得到浏览器输入的参数信息
		String name = req.getParameter("name");
		Integer age = Integer.parseInt(req.getParameter("age"));
		String gender = req.getParameter("gender");
		Student student = new Student(name, age, gender);
		//2、调用sevice
		boolean result = studentService.insert(student);
		System.out.println(result ? "成功" : "失败");
		//3、重定向
		resp.sendRedirect("/Java1807Web/findStudent");
	}
}
